Repository navigation
test: unit tests for string-utils and date-utils - #465
Draft
quantcode-agent[bot] wants to merge 1 commit into
Draft
quantcode-agent[bot] wants to merge 1 commit into
quantcode-agent[bot] wants to merge 1 commit into
Conversation
…rdCount and formatRelative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test/string-utils.test.tsandtest/date-utils.test.tsso every exported function has tests:capitalize,reverse,slugify,wordCount,truncate,formatRelative,isSameDayandaddDays. The tests cover normal cases and edge cases.truncatewas not implemented. It now cuts at a word boundary, counts the...towardmaxLength, hard-cuts when there is no usable boundary, and handles amaxLengthof 3 or less.wordCountsplit on single spaces. It now trims the input and splits on any run of whitespace.formatRelativeusedMath.floorfor days, so 36h showed as "1 day ago". It now usesMath.round, so 36h shows as "2 days ago", which is what the existing test expects.new Date(y, m, d)instead of parsing UTC date-only strings, which failed in America/* timezones.Test results
bun test test/string-utils.test.ts test/date-utils.test.ts: 65 pass, 0 fail. Checked under UTC, America/Los_Angeles, America/New_York, Australia/Sydney, Pacific/Kiritimati and Pacific/Pago_Pago.bunx tsc --noEmitpasses.calculator,validatorandtask-manager. The same 10 fail onmain, and those files were out of scope, so I left them alone.Assumptions
truncate.truncate(" hello", 7)returns" ...", because when the firstmaxLength - 3characters are all spaces the fallback keeps them. The length limit still holds.